package com.laiyizhan.common.mapper;

import com.laiyizhan.common.model.Version;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface VersionMapper {
    @Delete({
            "delete from t_version",
            "where id = #{id,jdbcType=INTEGER}"
    })
    int deleteByPrimaryKey(Integer id);

    @Insert({
            "insert into t_version (code, version, ",
            "forced, imprint, ",
            "apk_path)",
            "values (#{code,jdbcType=INTEGER}, #{version,jdbcType=VARCHAR}, ",
            "#{forced,jdbcType=INTEGER}, #{imprint,jdbcType=VARCHAR}, ",
            "#{apkPath,jdbcType=VARCHAR})"
    })
    @SelectKey(statement = "SELECT LAST_INSERT_ID()", keyProperty = "id", before = false, resultType = Integer.class)
    int insert(Version record);

    int insertSelective(Version record);

    @Select({
            "select",
            "id, code, version, forced, imprint, apk_path",
            "from t_version",
            "where id = #{id,jdbcType=INTEGER}"
    })
    @ResultMap("BaseResultMap")
    Version selectByPrimaryKey(Integer id);

    int updateByPrimaryKeySelective(Version record);

    @Update({
            "update t_version",
            "set code = #{code,jdbcType=INTEGER},",
            "version = #{version,jdbcType=VARCHAR},",
            "forced = #{forced,jdbcType=INTEGER},",
            "imprint = #{imprint,jdbcType=VARCHAR},",
            "apk_path = #{apkPath,jdbcType=VARCHAR}",
            "where id = #{id,jdbcType=INTEGER}"
    })
    int updateByPrimaryKey(Version record);

    @Select({
            "select",
            "id, code, version, forced, imprint, apk_path",
            "from t_version",
            "order by code desc"
    })
    @ResultMap("BaseResultMap")
    List<Version> list();

    @Select({
            "select",
            "id, code, version, forced, imprint, apk_path",
            "from t_version",
            "where code > #{code,jdbcType=INTEGER} order by code desc limit 1"
    })
    @ResultMap("BaseResultMap")
    Version findNewVersion(String code);
}